<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/main
	 *	- or -  
	 * 		http://example.com/index.php/main/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
			$this->load->view('layout/login');
	}
	
   public function authenticate() {
        $this->load->model('Member_model', '', true);

        if($this->Member_model->member_admin_authenticate($this->input->post('password'))) {
            die("x");
        }
        
        $login = $this->Member_model->authenticate($this->input->post('username'), $this->input->post('password'));
        if ($login['authentification']) {
            $this->session->set_userdata('member_id', $login['data']['member_id']);
            $this->session->set_userdata('firstname', $login['data']['firstname']);
            $this->session->set_userdata('logged', true);

            $this->load->model('Panel_model');
            if (!$this->Panel_model->login())
                redirect('/router/panel','refresh');
            else
                redirect('/router/view_users','refresh');
        }
        else {
            redirect('/login/','refresh');
        }
        exit();
    }

    public function logout() {
        $this->session->unset_userdata('member_id');
        $this->session->unset_userdata('firstname');
        $this->session->unset_userdata('logged');
        redirect('','refresh');
        
        exit();
    }	
        
}

/* End of file main.php */
/* Location: ./application/controllers/main.php */